<?php
/**
* @package Pages-and-Items (com_pi_pages_and_items)
* @version 1.5.7
* @copyright Copyright (C) 2006-2010 Carsten Engel. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @author http://www.pages-and-items.com
*/

//no direct access
if(!defined('_VALID_MOS') && !defined('_JEXEC')){
	die('Restricted access');
}


//globals (needed in 1.5)
//global $item_type, $sub_task, $pageId, $item_id, $class_pi->pi_config;

$item_type = $class_pi->get_var('item_type', '' );
$sub_task = $class_pi->get_var('sub_task', '' );
$pageId = $class_pi->get_var('pageId', '' );
$item_id = $class_pi->get_var('itemId', '' );

//check if user has permission to this itemtype
if(!$class_pi->check_useraccess_itemtype($item_type)){
	echo '<script> alert(\''._pi_lang_noitemtype.'\'); window.history.go(-1); </script>';
	exit();
}

//check if plugin actually exists
if (!file_exists(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/'.$item_type.'.php')){	
	echo '<script> alert(\''._pi_lang_itemtypenotinstalled.$item_type.'\'); window.history.go(-1); </script>';	
	exit();		
}

//if itemtype is not published, throw error
if (!strpos($class_pi->pi_config['itemtypes'], $item_type)){
	echo '<script> alert(\''._pi_lang_itemtypenotpublished.$item_type.'\'); window.history.go(-1); </script>';
	exit();
}

//get pluginspecific configuration
if (file_exists(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/'.$item_type.'.php')){
	$pi_plugin_config = $class_pi->get_itemtype_config($item_type);				
}

//get language for plugin, defaults to english
if (file_exists(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/language/'.$class_pi->pi_config['language'].'.php')){
	include(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/language/'.$class_pi->pi_config['language'].'.php');			
}else{			
	if(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/language/english.php'){
		include(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/language/english.php'); 
	}
}

//if joomla 1.0.x get javascript for editor
if(!defined('_JEXEC') ){
	//joomla version 1.0.x 				
	global $_MAMBOTS;
	$_MAMBOTS->loadBotGroup( 'editors-xtd' );		
	$mainframe->set( 'loadEditor', true );	

}//end if joomla 1.0.x 
	
//give headers in Joomla 1.5 a bit more spunk
$class_pi->spunk_up_headers_1_5();

?>

<table cellspacing="0" cellpadding="0" border="0" width="100%">
  <tr>
    <td valign="top" width="25%"><?php
		$class_pi->pages();
		?></td> 
    <td valign="top">		
		
		<form name="adminForm" method="post" action="" enctype="multipart/form-data">
		
			<input type="hidden" name="option" id="option" value="com_pi_pages_and_items" />
			<input type="hidden" name="task" value="plugin" />				
			<input type="hidden" name="pageId" id="page_id" value="<?php echo $pageId; ?>">			
			<input type="hidden" name="item_id" value="<?php echo $item_id; ?>">						
			<input type="hidden" name="item_type" value="<?php echo $item_type; ?>">										
		 
			<?php
			
			//get database joomla 1.5
			if( defined('_JEXEC') ){			
				$database = JFactory::getDBO();
			}
			
			//plugin-specific things										
			require_once(dirname(__FILE__).'/../../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/admin/'.$sub_task.'.php');
			
			
						
				
			?>			
		</form>
	</td>
  </tr>
</table>
<?php
	$class_pi->display_footer();
?>			